SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Report](
	[Id] [nvarchar](16) NOT NULL,
	[IsFault] [bit] NOT NULL,
	[MaxDays] [int] NOT NULL,
	[Endpoints] [nvarchar](4000) NOT NULL,
	[MessagePlusTags] [nvarchar](4000) NULL,
	[MessageMinusTags] [nvarchar](4000) NULL,
	[MessageFaultTags] [nvarchar](4000) NULL,
	[IndicatorPlusTags] [nvarchar](4000) NULL,
	[IndicatorMinusTags] [nvarchar](4000) NULL,
	[IndicatorFaultTags] [nvarchar](4000) NULL,
	[TimePlotSettings] [nvarchar](4000) NULL,
	[Data] [image] NULL,
	[LastRefreshed] [datetime] NULL,
 CONSTRAINT [PK_Report] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF) 
)  
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Endpoint](
	[Id] [nvarchar](16) NOT NULL,
	[Url] [nvarchar](255) NOT NULL,
	[BasicAuth] [nvarchar](255) NULL,
	[Frequency] [int] NOT NULL,
	[LastRetrieved] [datetime] NOT NULL,
 CONSTRAINT [PK_Endpoint] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF) 
) 
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[User](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[OpenId] [nvarchar](255) NOT NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF) 
) 
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Response](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[Endpoint_id] [nvarchar](16) NOT NULL,
	[Retrieved] [datetime] NOT NULL,
	[Data] [image] NOT NULL,
 CONSTRAINT [PK_Document] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF) 
)  
GO

ALTER TABLE [dbo].[Endpoint] ADD  CONSTRAINT [DF_Endpoint_BasicAuth]  DEFAULT (NULL) FOR [BasicAuth]
GO

ALTER TABLE [dbo].[Report] ADD  CONSTRAINT [DF_Report_IsFault]  DEFAULT ((0)) FOR [IsFault]
GO

ALTER TABLE [dbo].[Report] ADD  CONSTRAINT [DF_Report_MaxDays]  DEFAULT ((0)) FOR [MaxDays]
GO

ALTER TABLE [dbo].[Response]  WITH CHECK ADD  CONSTRAINT [FK_Response_Endpoint] FOREIGN KEY([Endpoint_id])
REFERENCES [dbo].[Endpoint] ([Id])
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Response] CHECK CONSTRAINT [FK_Response_Endpoint]
GO
